package yto.freemarker.springcloud.feign;

import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import yto.freemarker.springcloud.entity.User;

@FeignClient("service-provider-movie")
public interface UserFeignClient {


    /**
     * 方式一
     *
     * 正常请求，没有数据压缩的
     *
     * @param id
     * @return
     */
//    @RequestMapping(value = "/simple/{id}", method = RequestMethod.GET)
//    public User findById(@PathVariable("id") Long id);// 两个坑：1. @GetMapping不支持   2. @PathVariable得设置value
//
//    @RequestMapping(value = "/test", method = RequestMethod.POST)
//    public User posetUser(@RequestBody User user);
//
//    // 该请求不会成功，只要参数是复杂对象，即使指定了是GET方法，feign依然会以POST方法进行发送
//    @RequestMapping(value = "/get-test", method = RequestMethod.GET)
//    public User getUser(@PathVariable("username") String username, @PathVariable("age") Short age);


    /**
     *
     * 方式二
     *
     * 压缩请求，都是byte数据，不然乱码
     *
     * @param id
     * @return
     */

    @RequestMapping(value = "/simple/{id}", method = RequestMethod.GET)
    public ResponseEntity<byte[]> findById(@PathVariable("id") Long id);// 两个坑：1. @GetMapping不支持   2. @PathVariable得设置value

    @RequestMapping(value = "/test", method = RequestMethod.POST)
    public ResponseEntity<byte[]> posetUser(@RequestBody User user);

    // 该请求不会成功，只要参数是复杂对象，即使指定了是GET方法，feign依然会以POST方法进行发送
    @RequestMapping(value = "/get-test", method = RequestMethod.GET)
    public ResponseEntity<byte[]> getUser(@PathVariable("username") String username, @PathVariable("age") Short age);

}